// Package logger
// Created by GoLand
// @User: lenora
// @Date: 2024/1/14
// @Time: 16:56

package logger

import "go.uber.org/zap"

type ZapLogger struct {
	z *zap.Logger
}

func NewZapLogger(logger *zap.Logger) Logger {
	return &ZapLogger{z: logger}
}

func (l *ZapLogger) Debug(msg string, args ...Field) {
	l.z.Debug(msg, l.toArgs(args)...)
}

func (l *ZapLogger) Info(msg string, args ...Field) {
	l.z.Info(msg, l.toArgs(args)...)
}

func (l *ZapLogger) Error(msg string, args ...Field) {
	l.z.Error(msg, l.toArgs(args)...)
}

func (l *ZapLogger) Warn(msg string, args ...Field) {
	l.z.Warn(msg, l.toArgs(args)...)
}

func (l *ZapLogger) toArgs(args []Field) []zap.Field {
	res := make([]zap.Field, 0, len(args))
	for _, arg := range args {
		res = append(res, zap.Any(arg.Key, arg.Value))
	}
	return res
}
